import Setting from "./setting";
const env = require("./env");
const MODE = "spa"; //单页面形式渲染模式 (打包后将 dist目录覆盖到 public/home 目录下) 打包命令: npm run generate
module.exports = {
  buildDir: "nuxt-dist",
  mode: MODE,
  /*
   ** Headers of the page
   */
  head: {
    title: "",
    meta: [
      { charset: "utf-8" },
      { name: "apple-mobile-web-app-capable", content: "yes" },
      { name: "viewport", content: "width=device-width, initial-scale=1" },
      {
        hid: "http-equiv",
        "http-equiv": "X-UA-Compatible",
        content: "IE=edge",
      },
      {
        hid: "keywords",
        name: "keywords",
        content:
          "CRMEB 新零售社交电商 社交电商系统 小程序商城系统 公众号商城系统 商城系统源码 免费商城系统 商城系统开发 开源商城系统 CRMEB源码 微商城源码 多店商城系统 小程序直播电商系统 知识付费系统源码 SCRM 客户管理 客户营销系统 多商户商城 B2B2C B2C B2B O2O",
      },
      {
        hid: "description",
        name: "description",
        content:
          "CRMEB开源会员电商营销系统，依托社交营销应用场景，独创将用户管理系统与社交电商系统创新性深度集成，充分将公域流量转为私域流量，帮助企业快速积累用户并实现精准营销，一次购买永久享受免费升级服务免费提供升级教程。",
      },
    ],
    link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
    // script: [
    //   {src: `/api/get_script`, ssr: false}
    // ],
  },
  env: {
    NUXT_ENV: env[process.env.MODE],
  },
  /*
   ** Customize the progress-bar color
   */
  loading: { color: "#fff" },

  /*
   ** Plugins to load before mounting the App
   */
  plugins: [
    "~/plugins/axios",
    { src: "./assets/fonts/iconfont.js", ssr: false },
    { src: "~/plugins/vue-swiper.js", ssr: false },
    { src: "~/plugins/utils.js", ssr: false },
    { src: "~/plugins/debounce.js", ssr: false },
    { src: "~/plugins/element-ui", ssr: false },
    { src: "~/plugins/vueqr.js", ssr: false },
    { src: "~/plugins/vue-clipboard.js", ssr: false },
    "~/plugins/main",
    "~/plugins/dynamic-scripts.client.js",
  ],
  /*
   ** Nuxt.js modules
   */
  modules: ["@nuxtjs/axios", "@nuxtjs/auth", "cookie-universal-nuxt"],
  /*
   ** Global CSS
   */
  css: [
    "~assets/fonts/iconfont.css",
    "~assets/css/index.scss",
    { src: "swiper/dist/css/swiper.css" },
  ],

  router: {
    middleware: ["auth"],
    scrollBehavior(to, from, savedPosition) {
      // 如果有保存的位置（浏览器前进后退），使用保存的位置
      if (savedPosition) {
        return savedPosition;
      }
      // 否则总是滚动到页面顶部
      // 立即滚动到顶部，不使用延迟
      return { x: 0, y: 0 };
    },
  },

  auth: {
    strategies: {
      local1: {
        _scheme: "local",
        endpoints: {
          login: {
            url: "/login",
            method: "post",
            propertyName: "token",
          },
          logout: {
            url: "/logout",
            method: "get",
          },
          user: {
            url: "user",
            method: "get",
            propertyName: false,
          },
        },
      },
      local2: {
        _scheme: "local",
        endpoints: {
          login: {
            url: "/login/mobile",
            method: "post",
            propertyName: "token",
          },
          logout: {
            url: "/logout",
            method: "get",
          },
          user: {
            url: "user",
            method: "get",
            propertyName: false,
          },
        },
      },
      local3: {
        _scheme: "local",
        endpoints: {
          login: {
            url: "/pc/wechat_auth",
            method: "get",
            propertyName: "token",
          },
          logout: {
            url: "/logout",
            method: "get",
          },
          user: {
            url: "user",
            method: "get",
            propertyName: false,
          },
        },
      },
    },
    redirect: {
      login: "/login",
      logout: "/",
      callback: "/login",
      home: false,
    },
    cookie: {
      options: {
        maxAge: 60 * 60 * 24 * 7,
      },
    },
    localStorage: false,
  },

  axios: {
    baseURL: "",
    proxy: true, // 开启代理
    prefix: "/api", // 请求前缀（可选）
  },
  proxy: {
    "/api": {
      target: "https://www.liligroup.club",
      changeOrigin: true,
      pathRewrite: {
        changeOrigin: true, // 表示是否跨域
        "^/api": "/api", // 路径重写（保持原样）
      },
    },
  },
  /*
   ** Build configuration
   */
  distDir: "build",
  /*
   ** Build configuration
   */
  build: {
    publicPath: "/home/",
    publicPathFolder: MODE === "spa" ? "/" : "",
    /*
     ** You can extend webpack config here
     */
    // 添加对 .mjs 文件的处理
    extend(config, { isClient }) {
      // 解决 .mjs 文件的解析问题
      config.module.rules.push({
        test: /\.mjs$/,
        include: /node_modules/,
        type: "javascript/auto",
      });
    },
    // 添加需要转译的包
    transpile: ["@airwallex/components-sdk"],
    babel: {
      plugins: [
        [
          "component",
          {
            libraryName: "element-ui",
            styleLibraryName: "theme-chalk",
          },
        ],
      ],
    },
    loaders: {
      scss: {
        additionalData: `@use "@/assets/css/variables.scss" as *;`,
      },
      vue: {
        compilerOptions: {
          whitespace: "condense",
        },
      },
    },
  },

  server: {
    port: 10822,
    host: "0.0.0.0", // default: localhost
  },
};
